package com.example.administrator.caigou51.global;

import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;

import android.text.TextUtils;
import android.util.Log;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;

import com.ab.util.AbSharedUtil;
import com.ab.util.AbViewUtil;

import com.alibaba.fastjson.JSON;
import com.example.administrator.caigou51.EventBusClass.GotoFragment;
import com.example.administrator.caigou51.R;
import com.example.administrator.caigou51.activity.GBaseActivity;
import com.example.administrator.caigou51.activity.LoginActivity;
import com.example.administrator.caigou51.activity.MainActivity;
import com.example.administrator.caigou51.activity.MessageActivity;
import com.example.administrator.caigou51.activity.SearchActivity;
import com.example.administrator.caigou51.bean.CollectBean;
import com.example.administrator.caigou51.bean.GoodsDetailBean;
import com.example.administrator.caigou51.bean.OrderInfoBean;
import com.example.administrator.caigou51.bean.ShopCarBean;
import com.example.administrator.caigou51.bean.UserBean;
import com.example.administrator.caigou51.bean.UserCenterOtherBean;
import com.example.administrator.caigou51.recyclerCard.basic.MaterialListView;
import com.example.administrator.caigou51.recyclerCard.card.GoodsDetailCard;
import com.example.administrator.caigou51.util.ImageUtil;
import com.example.administrator.caigou51.util.ToastUtil;
import com.example.administrator.caigou51.widget.dialog.ShareDialog2;
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.cache.memory.impl.WeakMemoryCache;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import cn.jpush.android.api.JPushInterface;
import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.tencent.qq.QQ;
import cn.sharesdk.tencent.qzone.QZone;
import cn.sharesdk.wechat.friends.Wechat;
import cn.sharesdk.wechat.moments.WechatMoments;
import de.greenrobot.event.EventBus;


/**
 * Created by xyg on 2015/9/8.
 */
public class App extends Application {
    public static final int PassValue=1;//是否已验证0 未通过 未提交  1已通过  2正在审核
    public static final int CheckValue=2;
    public int screenWidth=0;//屏幕宽度
    public int screenHeight=0;//屏幕高度
    private static PopupWindow popupWindow = null;
    private static App instance;
    public static ImageLoader imageLoader = ImageLoader.getInstance();//1
    public static final String UserTag="UserTag";
    public static final String UserCenterOtherBeanTag="UserCenterOtherBeanTag";
    public static final String ShopCarTag="ShopCarTag";
    public static final String OrderListTag="OrderListTag";
    public static final String CollectBeanListTag="CollectBeanListTag";
    public static final String CollectBeanListServerTag="CollectBeanListServerTag";
    public static UserBean userBean;
    public static UserCenterOtherBean userCenterOtherBean;
    public static List<ShopCarBean> shopCarBeanList;
    public static List<OrderInfoBean> orderList;
    public static List<CollectBean> collectBeanList;
    public static List<CollectBean> collectBeanListServer;
    GoodsDetailBean goodsDetailBean;
    @Override
    public void onCreate() {
        super.onCreate();

        //LeakCanary.install(this);

        //设置崩溃处理
        CrashHandler crashHandler = CrashHandler.getInstance();
        crashHandler.init(getApplicationContext());
        instance = this;

        WindowManager windowManager = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
        Display display = windowManager.getDefaultDisplay();
        screenWidth = windowManager.getDefaultDisplay().getWidth();
        screenHeight = windowManager.getDefaultDisplay().getHeight();
        initImageLoader(getApplicationContext());

        imageLoader.init(new ImageLoaderConfiguration.Builder(this).memoryCache(new WeakMemoryCache()).build());

        JPushInterface.setDebugMode(true); 	// 设置开启日志,发布时请关闭日志
        JPushInterface.init(this);     		// 初始化 JPush
        JPushInterface.getRegistrationID(this);

        ShareSDK.initSDK(this);
    }

    public static App getInstance() {
        return instance;
    }

    /**
     * 描述：Toast提示文本.
     *
     * @param text 文本
     */
    public static void showToast(String text) {
        if (!TextUtils.isEmpty(text)) {
            android.widget.Toast.makeText(App.getInstance(), text, android.widget.Toast.LENGTH_SHORT).show();
        }

    }

    /**
     * 描述：Toast提示文本.
     *
     * @param resId 文本的资源ID
     */
    public static void showToast(int resId) {
        android.widget.Toast.makeText(App.getInstance(), "" + App.getInstance().getResources().getText(resId), android.widget.Toast.LENGTH_SHORT).show();
    }

    public static List<OrderInfoBean> getOrderList() {
        if (orderList==null)
        {
            String json=AbSharedUtil.getString(App.getInstance().getApplicationContext(),OrderListTag);

            if (!TextUtils.isEmpty(json))
            {
                orderList=JSON.parseArray(json,OrderInfoBean.class);
            }else
            {
                orderList=new ArrayList<>();
            }
        }
        if (orderList==null )
        {
            orderList=new ArrayList<>();
        }
        return orderList;
    }

    public static void saveCollectBeanList(List<CollectBean> collectBeanList) {
        AbSharedUtil.putString(App.getInstance().getApplicationContext(), CollectBeanListTag, JSON.toJSONString(collectBeanList));
    }
    public static void saveCollectBeanListServer(List<CollectBean> collectBeanList) {
        AbSharedUtil.putString(App.getInstance().getApplicationContext(), CollectBeanListServerTag, JSON.toJSONString(collectBeanList));
    }
    public static void saveOrderList(List<OrderInfoBean> orderInfoBeenList) {
        AbSharedUtil.putString(App.getInstance().getApplicationContext(), OrderListTag, JSON.toJSONString(orderInfoBeenList));
    }
    public static void saveShopCarList(List<ShopCarBean> shopCarBeanList) {
        AbSharedUtil.putString(App.getInstance().getApplicationContext(), ShopCarTag, JSON.toJSONString(shopCarBeanList));
    }
    public static List<CollectBean> getCollectBeanListServer() {

        if (collectBeanListServer==null)
        {
            String json=AbSharedUtil.getString(App.getInstance().getApplicationContext(),CollectBeanListServerTag);

            if (!TextUtils.isEmpty(json))
            {
                collectBeanListServer=JSON.parseArray(json,CollectBean.class);
            }else
            {
                collectBeanListServer=new ArrayList<>();
            }
        }
        if (collectBeanListServer==null )
        {
            collectBeanListServer=new ArrayList<>();
        }
        return collectBeanListServer;
    }
    public static List<CollectBean> getCollectBeanList() {

        if (collectBeanList==null)
        {
            String json=AbSharedUtil.getString(App.getInstance().getApplicationContext(),CollectBeanListTag);

            if (!TextUtils.isEmpty(json))
            {
                collectBeanList=JSON.parseArray(json,CollectBean.class);
            }else
            {
                collectBeanList=new ArrayList<>();
            }
        }
        if (collectBeanList==null )
        {
            collectBeanList=new ArrayList<>();
        }
        return collectBeanList;
    }
    public static List<ShopCarBean> getShopCarList() {

        if (shopCarBeanList==null)
        {
            String json=AbSharedUtil.getString(App.getInstance().getApplicationContext(),ShopCarTag);

            if (!TextUtils.isEmpty(json) )
            {
                shopCarBeanList=JSON.parseArray(json,ShopCarBean.class);
            }else
            {
                shopCarBeanList=new ArrayList<>();
            }
        }

        if (shopCarBeanList==null )
        {
            shopCarBeanList=new ArrayList<>();
        }
        return shopCarBeanList;
    }
    public static int getShopCarTotalCount() {

        int count=0;
        if (shopCarBeanList!=null)
        {
           for (ShopCarBean shopCarBean : shopCarBeanList)
           {
               count=count+shopCarBean.getNumber();
           }
        }

        return count;
    }
    public static ShopCarBean getShopCarBeanByID (GoodsDetailBean goodsDetailBean) {
        List<ShopCarBean> list= getShopCarList();
        if (list!=null)
        {
            for (ShopCarBean ShopCarBean :App.getShopCarList() )
            {
                if (ShopCarBean.getItemid().equals(goodsDetailBean.getItemid()))
                {
                   return ShopCarBean;
                }
            }
        }
        return null;
    }
    public static void saveUserCenterOtherBean(UserCenterOtherBean userCenterOtherBean) {
        if (userCenterOtherBean==null)
            AbSharedUtil.putString(App.getInstance().getApplicationContext(), UserCenterOtherBeanTag,"");
        else
            AbSharedUtil.putString(App.getInstance().getApplicationContext(), UserCenterOtherBeanTag, JSON.toJSONString(userCenterOtherBean));
    }
    public static UserCenterOtherBean getUserCenterOtherBean() {
        if (userCenterOtherBean==null)
        {
            String json=AbSharedUtil.getString(App.getInstance().getApplicationContext(),UserCenterOtherBeanTag);
            if (!TextUtils.isEmpty(json))
            {
                userCenterOtherBean=JSON.parseObject(json,UserCenterOtherBean.class);
            }
        }

        return userCenterOtherBean;
    }
    public static void saveUserBean(UserBean userBean) {
        if (userBean==null)
            AbSharedUtil.putString(App.getInstance().getApplicationContext(), UserTag,"");
        else
        AbSharedUtil.putString(App.getInstance().getApplicationContext(), UserTag, JSON.toJSONString(userBean));
    }
    public static UserBean getUserBean() {
        if (userBean==null)
        {
            String json=AbSharedUtil.getString(App.getInstance().getApplicationContext(),UserTag);
            if (!TextUtils.isEmpty(json))
            {
                userBean=JSON.parseObject(json,UserBean.class);
            }
        }

        return userBean;
    }
    public static void initImageLoader(Context context) {
        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
                context)
                .threadPriority(Thread.NORM_PRIORITY - 2)
                .denyCacheImageMultipleSizesInMemory()
                        // .memoryCache(new UsingFreqLimitedMemoryCache(4*1024*1024))
                .memoryCacheExtraOptions(480, 800)
                        // max width, max height
                .discCacheFileNameGenerator(new Md5FileNameGenerator())
                .tasksProcessingOrder(QueueProcessingType.LIFO)
                .denyCacheImageMultipleSizesInMemory()// 自动缩放
//				.writeDebugLogs() // Remove for release app
                .defaultDisplayImageOptions(ImageUtil.OptionsNormal())
                .build();
        // Initialize ImageLoader with configuration.
        ImageLoader.getInstance().init(config);
    }

    /**
     * 这个方法是用来判断是否是网络图片来的
     * 不是网络图片就加file
     *
     * @param uri
     * @param imageView
     * @param options
     */
    public static void displayImageHttpOrFile(String uri, ImageView imageView, DisplayImageOptions options) {
        if (uri != null) {
            if (uri.startsWith("http://")) {
                imageLoader.displayImage(uri, imageView, options);
            } else if (uri.startsWith("file://")) {
                imageLoader.displayImage(uri, imageView, options);
            } else if (uri.startsWith("https://")) {
                imageLoader.displayImage(uri, imageView, options);
            } else {
                imageLoader.displayImage("file://" + uri, imageView, options);
            }
        } else {
            imageLoader.displayImage("", imageView, options);
        }
    }

    float y1;
    float y2;
    float x1;
    float x2;
    public void setScrollListViewHideBottom(MaterialListView listview, final GBaseActivity activity)
    {

        listview.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                //继承了Activity的onTouchEvent方法，直接监听点击事件
                if(event.getAction() == MotionEvent.ACTION_DOWN) {
                    //当手指按下的时候
                    x1 = event.getX();
                    y1 = event.getY();
                }
                if(event.getAction() == MotionEvent.ACTION_UP) {
                    //当手指离开的时候
                    x2 = event.getX();
                    y2 = event.getY();
                    if(y1 - y2 > AbViewUtil.scaleValue(App.getInstance(),20)) {
                        //   Toast.makeText(MainActivity.this, "向上滑", Toast.LENGTH_SHORT).show();
                        activity.getBottomBar().setVisibility(View.GONE);
                    } else if(y2 - y1 > AbViewUtil.scaleValue(App.getInstance(),20)) {
                        // Toast.makeText(MainActivity.this, "向下滑", Toast.LENGTH_SHORT).show();
                        activity.getBottomBar().setVisibility(View.GONE);
                    } else if(x1 - x2 > AbViewUtil.scaleValue(App.getInstance(),20)) {
                        //  Toast.makeText(MainActivity.this, "向左滑", Toast.LENGTH_SHORT).show();
                    } else if(x2 - x1 > AbViewUtil.scaleValue(App.getInstance(),20)) {
                        //  Toast.makeText(MainActivity.this, "向右滑", Toast.LENGTH_SHORT).show();
                    }
                }
                return false;
            }
        });
    }

    public static void showPopupWindow(View view,final Context context,int ox,int oy) {

        // 一个自定义的布局，作为显示的内容
        View contentView = LayoutInflater.from(context).inflate(
                R.layout.popwindow_more_item, null);
        AbViewUtil.scaleContentView((ViewGroup) contentView);
        LinearLayout linearlayoutShouYe;
        LinearLayout linearlayoutShouSuo;
        LinearLayout linearlayoutWoDe;
        LinearLayout  linearlayoutXiaoxi;
        LinearLayout linearLayoutMain;
        // 设置按钮的点击事件
        linearlayoutShouYe = (LinearLayout) contentView.findViewById(R.id.linearlayoutShouYe);//linearlayoutShouYe.setOnClickListener(this);
        linearlayoutShouYe.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                    Intent intentM=new Intent(App.getInstance().getApplicationContext(),MainActivity.class);
                intentM.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                App.getInstance().getApplicationContext().startActivity(intentM);

                EventBus.getDefault().post(new GotoFragment(MainActivity.TAB_ShouYe));
            }
        });

        linearlayoutShouSuo = (LinearLayout) contentView.findViewById(R.id.linearlayoutShouSuo);
        linearlayoutShouSuo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(App.getInstance().getApplicationContext(), SearchActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                App.getInstance().getApplicationContext().startActivity(intent);
            }
        });

        linearlayoutXiaoxi = (LinearLayout) contentView.findViewById(R.id.linearlayoutXiaoxi);
        linearlayoutXiaoxi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (App.getUserBean()!=null) {
                    Intent intent = new Intent(App.getInstance().getApplicationContext(), MessageActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    App.getInstance().getApplicationContext().startActivity(intent);
                }else
                {
                    Intent intent=new Intent(App.getInstance().getApplicationContext(), LoginActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    App.getInstance().getApplicationContext().startActivity(intent);
                }
            }
        });

        linearlayoutWoDe = (LinearLayout) contentView.findViewById(R.id.linearlayoutWoDe);
        linearlayoutWoDe.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (App.getUserBean()==null)
                {
                    Intent intent5=new Intent(App.getInstance().getApplicationContext(),LoginActivity.class);
                    intent5.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    App.getInstance().getApplicationContext().startActivity(intent5);
                    return;
                }
                Intent intentM=new Intent(App.getInstance().getApplicationContext(),MainActivity.class);
                intentM.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                App.getInstance().getApplicationContext().startActivity(intentM);
                EventBus.getDefault().post(new GotoFragment(MainActivity.TAB_GenRenZhongXin));
            }
        });
    /*    linearlayoutWoDe = (LinearLayout) contentView.findViewById(R.id.linearlayoutWoDe);//linearlayoutWoDe.setOnClickListener(this);
        linearlayoutWoDe.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ((GBaseActivity)context).finish();
                EventBus.getDefault().post(new UpdateFragment(MainActivity.TAB_GenRenZhongXin));
            }
        });
        linearlayoutFenXiang = (LinearLayout) contentView.findViewById(R.id.linearlayoutFenXiang);//linearlayoutFenXiang.setOnClickListener(this);
        linearlayoutFenXiang.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popupWindow.dismiss();
                showShareDialog(context);
            }
        });*/
        linearLayoutMain= (LinearLayout) contentView.findViewById(R.id.linearLayoutMain);

        int xm=AbViewUtil.scaleValue(context,258);
        int ym=AbViewUtil.scaleValue(context,360);
        linearLayoutMain.getLayoutParams().height=ym;
        linearLayoutMain.getLayoutParams().width=xm;


        //  AbViewUtil.scaleContentView((ViewGroup) popupWindow.getContentView());
        popupWindow = new PopupWindow(contentView,
                LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, true);
        popupWindow.getContentView().setTag(AbViewUtil.NotScale);
        popupWindow.setTouchable(true);

        popupWindow.setTouchInterceptor(new View.OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {

                Log.e("mengdd", "onTouch : ");

                return false;
                // 这里如果返回true的话，touch事件将被拦截
                // 拦截后 PopupWindow的onTouchEvent不被调用，这样点击外部区域无法dismiss
            }
        });

        // 如果不设置PopupWindow的背景，无论是点击外部区域还是Back键都无法dismiss弹框
        // 我觉得这里是API的一个bug
        //  popupWindow.setBackgroundDrawable(getResources().getDrawable(new BitmapDrawable());
        popupWindow.setBackgroundDrawable(new BitmapDrawable());

        int x=AbViewUtil.scaleValue(context,ox);
        int y=AbViewUtil.scaleValue(context,oy);
        // 设置好参数之后再show
        popupWindow.showAsDropDown(view,x,y);
        // popupWindow.showAtLocation(view, Gravity.RIGHT|Gravity.BOTTOM, 0, 0);
    }
    static ShareDialog2 shareDialog;
    public static void showShareDialog(final Context context, final GoodsDetailCard goodsDetailCard) {

        ShareDialog2.ShareOnClick shareOnClick =new ShareDialog2.ShareOnClick() {
            @Override
            public void toShare(View view) {
                switch (view.getId()) {
                    case R.id.linearLayout_penyouquan:
                        share2weixinfriend(1,context,goodsDetailCard);
                        shareDialog.dismiss();
                        break;
                    case R.id.linearLayout_weixin:
                        share2weixin(0,context,goodsDetailCard);
                        shareDialog.dismiss();
                        break;
                    case R.id.linearLayout_qq:
                        share2qq(0,context,goodsDetailCard);
                        shareDialog.dismiss();
                        break;
                    case R.id.linearLayout_qqzone:
                        share2qqZone(0,context,goodsDetailCard);
                        shareDialog.dismiss();
                        break;
                }
            }
        };
        shareDialog = new ShareDialog2(context, shareOnClick);
        Window window = shareDialog.getWindow();
        window.setGravity(Gravity.BOTTOM);  //此处可以设置dialog显示的位置
        window.setWindowAnimations(R.style.AnimBottom);  //添加动画
        shareDialog.show();
    }
    private static void share2weixin(int flag,Context context,GoodsDetailCard goodsDetailCard) {
//http://www.51caiyao.com/mall/h5_show.php?itemid=商品ID&uid=用户ID

        ShareSDK.initSDK(context);
        Wechat.ShareParams sp = new Wechat.ShareParams();
        sp.setShareType(Wechat.SHARE_WEBPAGE);
        sp.setTitle(goodsDetailCard.getGoodsDetailBean().getTitle());
        sp.setText(Constant.SystemContext.shareText);
        sp.setUrl("http://www.51caiyao.com/mall/h5_show.php?itemid="+goodsDetailCard.getGoodsDetailBean().getItemid()+"&uid="+App.getUserBean().getUserid());
        sp.setImageUrl(goodsDetailCard.getGoodsDetailBean().getImages().get(0));
        Platform wechat = ShareSDK.getPlatform(Wechat.NAME);
        wechat.share(sp);
    }
    private static void share2weixinfriend(int flag,Context context,GoodsDetailCard goodsDetailCard) {
        ShareSDK.initSDK(context);
        Wechat.ShareParams sp = new Wechat.ShareParams();
        sp.setShareType(Wechat.SHARE_WEBPAGE);
        sp.setTitle(goodsDetailCard.getGoodsDetailBean().getTitle());
        sp.setText(Constant.SystemContext.shareText);
        sp.setUrl("http://www.51caiyao.com/mall/h5_show.php?itemid="+goodsDetailCard.getGoodsDetailBean().getItemid()+"&uid="+App.getUserBean().getUserid());
        sp.setImageUrl(goodsDetailCard.getGoodsDetailBean().getImages().get(0));
        Platform wechat = ShareSDK.getPlatform(WechatMoments.NAME);

        wechat.share(sp);
    }

    private static void share2qq(int flag, final Context context, GoodsDetailCard goodsDetailCard) {
        ShareSDK.initSDK(context);
        QQ.ShareParams sp = new QQ.ShareParams();
        sp.setShareType(QQ.SHARE_WEBPAGE);
        sp.setTitle(goodsDetailCard.getGoodsDetailBean().getTitle());
        sp.setText(Constant.SystemContext.shareText);
        sp.setTitleUrl("http://www.51caiyao.com/mall/h5_show.php?itemid="+goodsDetailCard.getGoodsDetailBean().getItemid()+"&uid="+App.getUserBean().getUserid());
       // sp.setUrl("http://www.51caiyao.com/mall/h5_show.php?itemid="+goodsDetailCard.getGoodsDetailBean().getItemid()+"&uid="+App.getUserBean().getUserid());
        sp.setImageUrl(goodsDetailCard.getGoodsDetailBean().getImages().get(0));
        Platform qqWeiboPlatForm = ShareSDK.getPlatform(QQ.NAME);
        qqWeiboPlatForm.setPlatformActionListener(new PlatformActionListener() {
            @Override
            public void onComplete(final Platform platform, int i, HashMap<String, Object> hashMap) {
                ((GBaseActivity)context).runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        ToastUtil.showToast("分享成功！");

                    }
                });
            }

            @Override
            public void onError(final Platform platform, int i, final Throwable throwable) {
                ((GBaseActivity)context).runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        ToastUtil.showToast(throwable.toString());
                    }
                });
            }

            @Override
            public void onCancel(Platform platform, int i) {
                ((GBaseActivity)context).runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        ToastUtil.showToast("取消分享！");
                    }
                });
            }
        }); // 设置分享事件回调
        qqWeiboPlatForm.share(sp);
    }

    private static void share2qqZone(int flag, final Context context, GoodsDetailCard goodsDetailCard) {
        ShareSDK.initSDK(context);
        QZone.ShareParams sp = new QZone.ShareParams();
        sp.setShareType(QZone.SHARE_WEBPAGE);
        sp.setTitle(goodsDetailCard.getGoodsDetailBean().getTitle());
        sp.setText(Constant.SystemContext.shareText);
        sp.setTitleUrl("http://www.51caiyao.com/mall/h5_show.php?itemid="+goodsDetailCard.getGoodsDetailBean().getItemid()+"&uid="+App.getUserBean().getUserid());
      //  sp.setUrl("http://www.51caiyao.com/mall/h5_show.php?itemid="+goodsDetailCard.getGoodsDetailBean().getItemid()+"&uid="+App.getUserBean().getUserid());
        sp.setImageUrl(goodsDetailCard.getGoodsDetailBean().getImages().get(0));
        Platform qZonePlatForm = ShareSDK.getPlatform(QZone.NAME);
        qZonePlatForm.setPlatformActionListener(new PlatformActionListener() {
            @Override
            public void onComplete(final Platform platform, int i, HashMap<String, Object> hashMap) {
                ((GBaseActivity)context).runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        ToastUtil.showToast("分享成功！");
                    }
                });
            }

            @Override
            public void onError(final Platform platform, int i, final Throwable throwable) {
                ((GBaseActivity)context).runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        ToastUtil.showToast(throwable.toString());
                    }
                });
            }

            @Override
            public void onCancel(Platform platform, int i) {
                ((GBaseActivity)context).runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        ToastUtil.showToast("取消分享！");
                    }
                });
            }
        }); // 设置分享事件回调
        qZonePlatForm.share(sp);
    }
}
